package edu.wit.acl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.wit.acl.entity.UserRole;
import edu.wit.acl.mapper.UserRoleMapper;
import edu.wit.acl.service.UserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-01-12
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    @Override
    public int selectRoleNums(String roleId) {
        return baseMapper.selectCount(new QueryWrapper<UserRole>().eq("role_id",roleId));
    }

    @Override
    public String selectRoleIdByUserId(String userId) {
        UserRole userRole=baseMapper.selectOne(new QueryWrapper<UserRole>().eq("user_id",userId));

        if (userRole == null) {
            return null;
        }

        return userRole.getRoleId();
    }

    @Override
    public List<UserRole> selectUserIdsByRoleId(String roleId) {
        QueryWrapper<UserRole> wrapper = new QueryWrapper<>();
        wrapper.eq("roleId",roleId);
        List<UserRole> userRoles = baseMapper.selectList(wrapper);
        return userRoles;
    }
}
